//
//  PhotoAlbumView.m
//  PigMarket
//
//  Created by Felix on 2019/3/23.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "PhotoAlbumView.h"

@interface PhotoAlbumView ()

/**
 title
 */
@property (nonatomic , strong) UILabel *title;

/**
 detail
 */
@property (nonatomic , strong) UILabel *detail;

/**
 gtImageView
 */
@property (nonatomic , strong) UIImageView *gtImageView;

/**
 line
 */
@property (nonatomic , strong) UILabel *line;

/**
 photoScrollView
 */
@property (nonatomic , strong) UIScrollView *photoScrollView;

/**
 contentView
 */
@property (nonatomic , strong) UIView *contentView;



@end

@implementation PhotoAlbumView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.title];
    [self addSubview:self.detail];
    [self addSubview:self.gtImageView];
    [self addSubview:self.line];
    [self addSubview:self.photoScrollView];
    [self.photoScrollView addSubview:self.contentView];
    [self initPhotos];
}

- (void)initLayout {
    // 布局子控件
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(12);
    }];
    [self.gtImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.mas_equalTo(self.title.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
    [self.detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.gtImageView.mas_left).offset(4);
        make.centerY.mas_equalTo(self.title.mas_centerY);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.title.mas_bottom).offset(12);
        make.height.mas_equalTo(1);
    }];
    [self.photoScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.line.mas_bottom).offset(12);
        make.bottom.mas_equalTo(-12);
    }];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
//        make.height.mas_equalTo(60);
    }];
}

- (void)initPhotos {
    CGFloat imageWH = 60;
    CGFloat padding = 5;
    for (int i = 0; i < 6; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"user_header"];
        [self.contentView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_equalTo(0);
            make.left.mas_equalTo(i * (imageWH + padding) + 12);
            make.size.mas_equalTo(CGSizeMake(imageWH, imageWH));
            if (i == 5) {
                make.right.mas_equalTo(-12);
            }
        }];
//        imageView.frame = CGRectMake(i * (imageWH + padding) + 12, 0, imageWH, imageWH);
    }
}

#pragma mark - getter and setter

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor colorWithHexString:@"#262626"];
        _title.font = [UIFont middleFont];
        _title.text = @"我的照片";
    }
    return _title;
}
- (UILabel *)detail {
    if (!_detail) {
        _detail = [[UILabel alloc] init];
        _detail.textColor = [UIColor colorWithHexString:@"#999999"];
        _detail.font = [UIFont smallFont];
        _detail.text = @"查看全部照片";
    }
    return _detail;
}
- (UIImageView *)gtImageView {
    if (!_gtImageView) {
        _gtImageView = [[UIImageView alloc] init];
        _gtImageView.image = [UIImage imageNamed:@"user_gt"];
    }
    return _gtImageView;
}
- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = [UIColor dividerColor];
    }
    return _line;
}
- (UIScrollView *)photoScrollView {
    if (!_photoScrollView) {
        _photoScrollView = [[UIScrollView alloc] init];
        _photoScrollView.showsVerticalScrollIndicator = NO;
        _photoScrollView.showsHorizontalScrollIndicator = NO;
    }
    return _photoScrollView;
}
- (UIView *)contentView {
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
    }
    return _contentView;
}

@end
